﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExpiredDomainSearch.Manager;

namespace ExpiredDomainSearch
{
    public partial class Site : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Cookies.AllKeys.Contains("csearchparam"))
            {
                SearchParam param = Common.DeSerialize(EncryptionHelper.DecryptString(Request.Cookies["csearchparam"].Value));
                txtKeyword.Text = param.Keyword;
                ddlTLD.SelectedValue = param.TLD;
                ddlPosition.SelectedValue = param.Position;
                ddlHypens.SelectedValue = param.Hypen;
                ddlNumbers.SelectedValue = param.Numbers;
                ddlMaxLength.SelectedValue = param.MaxLength;
                ddlDeletion.SelectedValue = param.Deletion;
            }
        }

        protected void btnSearch_Click(object sender, ImageClickEventArgs e)
        {
            SearchParam param = new SearchParam()
            {
                Deletion = ddlDeletion.SelectedValue,
                Hypen = ddlHypens.SelectedValue,
                Keyword = txtKeyword.Text,
                MaxLength = ddlMaxLength.SelectedValue,
                Numbers = ddlNumbers.SelectedValue,
                Position = ddlPosition.SelectedValue,
                TLD = ddlTLD.SelectedValue
            };

            string paramXml = Common.Serialize(param);
            Response.Cookies.Add(new HttpCookie("csearchparam", EncryptionHelper.EncryptString(paramXml)));
            Response.Cookies["csearchparam"].Expires = DateTime.Now.AddHours(1);
            Response.Redirect("Search.aspx");
        }
    }
}